﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：部门选择
 */
var dfopid = request('dfopid');
var selectValue = request('selectValue');
var selectedRow;
var refreshGirdData;
var acceptClick;

var companyId = request("companyId");
var departmentId = request("departmentId");
var keyword = request("keyword");
var controlName = request("controlName");

var bootstrap = function ($, learun) {
    "use strict";
    var item = {value: '', text: ''};

    var page = {
        init: function () {
            page.bind();
            page.initGrid();
            page.search({keyword: keyword});
        },
        bind: function () {
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });
            $("#txt_Keyword").keypress(function (even) {
                if (even.which == 13) {
                    var keyword = $(this).val();
                    page.search({keyword: keyword});
                }
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'users?access_token=' + config.getToken().access_token,
                headData: [
                    {label: '账号', name: 'userName', width: 160, align: 'left'},
                    {label: '姓名', name: 'realName', width: 180, align: 'left'},
                    {label: 'id', name: 'id', width: 1, align: 'left', hidden: true},
                ],
                dblclick: function (row) {
                    item = {value: row.id, text: row.realName};
                 
                    top.lrGirdLayerEditCallBack(row);
                    learun.layerClose(window.name);
                },
                isPage: true,
                reloadSelected: true,
                isTree: false,
                mainId: 'id'
            });
        },
        search: function (param) {
            param = param || {};
            param.companyId = companyId;
            param.departmentId = departmentId;
            param.status = 1;
            // param.keyword = keyword;
            $('#gridtable').jfGridSet('reload', param);
        }
    };
    refreshGirdData = function () {
        page.search();
    };

    // 保存数据
    acceptClick = function (callBack) {
        var value = $('#gridtable').jfGridValue('id');
        var text = $('#gridtable').jfGridValue('realName');
        var item = {value: value, text: text};
        if (learun.checkrow(value)) {
            callBack(item, dfopid);
            return true;
        } else {
            return false;
        }
    };
    page.init();
}